package www.openteam.com.model.business;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.AddDeliverNote;
import www.openteam.com.bean.ShipBus;
import www.openteam.com.bean.ShipBusList;
import www.openteam.com.bean.UpdateInfo;

/**
 * Created by Administrator on 2019-08-16.
 */

public class LoadListModel extends BaseModel {
    public void getShipBus(String rdsno, final ShipBustListener shipBustListener) {
        httpApiService.getShipBus(rdsno).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ShipBus>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        shipBustListener.fail(e.getMessage());
                    }

                    @Override
                    public void onNext(ShipBus shipBus) {
                        shipBustListener.success(shipBus);
                    }
                });

    }

    public void getShipBusList(String zbid, final ShipBustListListener shipBustListListener) {
        httpApiService.getShipBusList(zbid).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ShipBusList>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        shipBustListListener.fail(e.getMessage());
                    }

                    @Override
                    public void onNext(ShipBusList shipBus) {
                        shipBustListListener.success(shipBus);
                    }
                });

    }

    public void addDeliverNote(String rdsno, final AddDeliverNoteListener addDeliverNoteListener) {
        httpApiService.addDeliverNote(rdsno).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<AddDeliverNote>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        addDeliverNoteListener.fail(e.getMessage());
                    }

                    @Override
                    public void onNext(AddDeliverNote addDeliverNote) {
                        addDeliverNoteListener.success(addDeliverNote);
                    }
                });

    }

    public void insertDeliverNote(String group,String ids , final InsertDeliverNoteListener insertDeliverNoteListener) {
        httpApiService.insertDelryNote(group,ids).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<UpdateInfo>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        insertDeliverNoteListener.fail(e.getMessage());
                    }

                    @Override
                    public void onNext(UpdateInfo info) {
                        insertDeliverNoteListener.success(info);
                    }
                });

    }

    public void deleteLoadList(String zbid , final DeleteLoadListListener deleteLoadListListener) {
        httpApiService.deleteLoadingListNote(zbid).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<UpdateInfo>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        deleteLoadListListener.fail(e.getMessage());
                    }

                    @Override
                    public void onNext(UpdateInfo info) {
                        deleteLoadListListener.success(info);
                    }
                });

    }

    public void audit(String id,String checker ,String checkDate, final AuditListener auditListener) {
        httpApiService.audit_ldstlst(id,checker,checkDate).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<UpdateInfo>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        auditListener.fail(e.getMessage());
                    }

                    @Override
                    public void onNext(UpdateInfo info) {
                        auditListener.success(info);
                    }
                });

    }

    public void unaudit(String id, final UnAuditListener unauditListener) {
        httpApiService.unaudit_ldstlst(id).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<UpdateInfo>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        unauditListener.fail(e.getMessage());
                    }

                    @Override
                    public void onNext(UpdateInfo info) {
                        unauditListener.success(info);
                    }
                });

    }

    public interface ShipBustListener {
        void success(ShipBus shipBus);

        void fail(String msg);
    }

    public interface ShipBustListListener {
        void success(ShipBusList shipBusList);

        void fail(String msg);
    }

    public interface AddDeliverNoteListener {
        void success(AddDeliverNote addDeliverNote);

        void fail(String msg);
    }

    public interface InsertDeliverNoteListener {
        void success(UpdateInfo info);

        void fail(String msg);
    }

    public interface DeleteLoadListListener {
        void success(UpdateInfo info);

        void fail(String msg);
    }

    public interface AuditListener {
        void success(UpdateInfo info);

        void fail(String msg);
    }

    public interface UnAuditListener {
        void success(UpdateInfo info);

        void fail(String msg);
    }
}
